home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / minix / up1510b.tgz / up1510b / src / kernel / stdskclks.s < prev    next >
Text File  |  1990-07-23  |  8KB  |  420 lines

  1. #ifdef CLOCKS
  2. #include <minix/config.h>
  3. #if (NR_DRIVES > 0)    /* assume: no hard disk; no controller */
  4.         .define _rd1byte
  5.         .define _wr1byte
  6.     .define _getsupra
  7.     .define _geticd
  8.  
  9.         .sect   .text
  10.         .sect   .rom
  11.         .sect   .data
  12.         .sect   .bss
  13.  
  14.         .sect   .text
  15.  
  16. dma_base        =               0xff8604
  17. dma_data        =               0
  18. dma_cont        =               2
  19.  
  20. select          =               0x10
  21. sck_en          =               0x08
  22.  
  23. write           =               0x80
  24.  
  25. clk_dev =               6
  26. clk_adr =               clk_dev*32
  27. !
  28. ! moves the byte in d0 to the clock chip
  29. !  uses d1, a0 must point to the dma channel
  30. !
  31.  
  32. _wr1byte:
  33.         clr.w   d0
  34.         move.b  5(a7), d0
  35.         lea     dma_base, a0
  36.         move.w          #7, d1
  37.         swap            d0
  38.         move.w          #clk_adr+select+sck_en, d0
  39.  
  40. wrloop:         lsr.w           #1, d0
  41.         swap            d0
  42.  
  43.         roxl.b          #1, d0
  44.         swap            d0
  45.         roxl.w          #1, d0
  46.         move.w          d0, dma_data(a0)
  47.  
  48.         dbra            d1, wrloop
  49.  
  50.         rts
  51.  
  52. !
  53. ! moves a byte into d0 from the clock chip
  54. !  uses d1, a0 must point to the dma channel
  55. !
  56.  
  57. _rd1byte:
  58.         lea     dma_base, a0
  59.         move.w          #7, d1
  60.  
  61. rdloop:         swap            d0
  62.  
  63.         move.w          #clk_adr+select+sck_en, dma_data(a0)
  64.         move.w          dma_data(a0), d0
  65.  
  66.         roxr.b          #1, d0
  67.         swap            d0
  68.         roxl.b          #1, d0
  69.  
  70.         dbra            d1, rdloop
  71.  
  72.         rts
  73.  
  74.     .sect    .text
  75.  
  76. !=============supra clock support here ==============
  77. bsy_wait:
  78.     link    a6,#0x0        ! 4e56 0000
  79.     bra    bsy2        ! 6018
  80. bsy1:
  81.     move.l    gpip_a,a0        ! 2079 0000 0d68
  82.     move.b    (a0),d0        ! 1010
  83.     ext      d0        ! 4880
  84.     and      #0x20,d0        ! c07c 0020
  85.     tst      d0        ! 4a40
  86.     bne    bsy2        ! 6606
  87.     move    #0x0,d0        ! 303c 0000
  88.     bra    bsy3        ! 6010
  89. bsy2:
  90.     move.l    0x8(a6),d0        ! 202e 0008
  91.     sub.l    #1,0x8(a6)        ! 53ae 0008
  92.     tst.l    d0        ! 4a80
  93.     bne    bsy1        ! 66dc
  94.     move    #0xffff,d0        ! 303c ffff
  95. bsy3:
  96.     unlk    a6        ! 4e5e
  97.     rts        ! 4e75
  98.  
  99. !getsupclk(cntlr,index) index counts
  100. getsupclk:
  101.     cntlr = 0x8
  102.     index = 0xa
  103.     status = -0x2
  104.     retval = -0x6
  105.     temp1 = -0x4
  106. !fffe:
  107.     FDC=0x80
  108.     HDC=0x8
  109.     A0=0x2
  110.  
  111.     link    a6,#0xfff6        ! 4e56 fff6
  112.     move    #0xff9c,retval(a6)        ! 3d7c ff9c fffa
  113.     move.l    dma_mode_a,a0        ! 2079 0000 0d64
  114.     move    #FDC+HDC,(a0)        ! 30bc 0088
  115.     move    cntlr(a6),d0        ! 302e 0008
  116.     ext.l    d0        ! 48c0
  117. !shift left  16 + 5
  118.     move.l    #16+5,d3        ! 263c 0000 0015
  119.     asl.l    d3,d0        ! e7a0
  120. !called as: 0xd,0xa,9,8,7,4,2,0
  121.     move    index(a6),d1        ! 322e 000a
  122.     ext.l    d1        ! 48c1
  123.     asl.l    #8,d1        ! e181
  124.     asl.l    #8,d1        ! e181
  125.     or.l    d1,d0        ! 8081
  126.     or.l    #0x8a,d0        ! 80bc 0000 008a
  127. ![ctlr-3][index-5]|[0x8a-16]
  128.     move.l    dma_data_a,a0        ! 2079 0000 0d6c
  129.     move.l    d0,(a0)        ! 2080
  130.     move.l    #0xa,-(a7)        ! 2f3c 0000 000a
  131.     jsr    bsy_wait        ! 4eb9 0000 00b6
  132.     add.l    #4,a7        ! 588f
  133.     move    d0,status(a6)        ! 3d40 fffe
  134.     move    status(a6),d0        ! 302e fffe
  135.     beq    h194        ! 673c
  136.  
  137. !timed out
  138.     move.l    dma_data_a,a0        ! 2079 0000 0d70
  139.     move    (a0),temp1(a6)        ! 3d50 fffc
  140.     move.l    #0xa,-(a7)        ! 2f3c 0000 000a
  141.     jsr    bsy_wait        ! 4eb9 0000 00b6
  142.     add.l    #4,a7        ! 588f
  143.     move    d0,status(a6)        ! 3d40 fffe
  144.     move    status(a6),d0        ! 302e fffe
  145.     beq    h194        ! 671a
  146.  
  147. !timed out
  148.     move.l    dma_mode_a,a0        ! 2079 0000 0d64
  149.     move    #FDC+HDC+A0,(a0)        ! 30bc 008a
  150.     move.l    dma_data_a,a0        ! 2079 0000 0d70
  151.     move    (a0),d0        ! 3010
  152.     and      #0xff,d0        ! c07c 00ff
  153.     move    d0,retval(a6)        ! 3d40 fffa
  154. h194:
  155.     move.l    dma_mode_a,a0        ! 2079 0000 0d64
  156.     move    #FDC,(a0)        ! 30bc 0080
  157.     move.l    dma_data_a,a0        ! 2079 0000 0d70
  158.     move    (a0),temp1(a6)        ! 3d50 fffc
  159.     move    retval(a6),d0        ! 302e fffa
  160.     unlk    a6        ! 4e5e
  161.     rts        ! 4e75
  162.  
  163. get_clock_channel:
  164.     link    a6,#0xfffe        ! 4e56 fffe
  165.     move    #0x6,d0
  166.     unlk    a6        ! 4e5e
  167.     rts        ! 4e75
  168.  
  169. !date format:
  170. ! 0-4    (1f)    day    1-31
  171. ! 5-8    >>5 (f)    month    1-12
  172. ! 9-15    >>9 (7f) year    0-119  year 0 == 1980
  173. !
  174. !time format:
  175. ! 0-4    (1f)    2sec    0-29
  176. ! 5-10    >>5 (3f) min    0-59
  177. ! 11-15    >>11 (3f) hour    0-59
  178. !
  179. _getsupra:
  180.     chan = -0x2
  181.     count= -0x4
  182.     date = -0x6
  183.     time = -0x8
  184.  
  185.     link    a6,#0xfff8        ! 4e56 fff8
  186.     jsr    get_clock_channel        ! 4eb9 0000 01c8
  187.     move    d0,chan(a6)        ! 3d40 fffe
  188.     tst      chan(a6)        ! 4a6e fffe
  189.     blt    sup3        ! 6d00 0116
  190. !get char 0xd
  191.     move    #0xd,-(a7)        ! 3f3c 000d
  192.     move    chan(a6),-(a7)        ! 3f2e fffe
  193.     jsr    getsupclk        ! 4eb9 0000 00e8
  194.     add.l    #4,a7        ! 588f
  195.     and      #0x80,d0        ! c07c 0080
  196.     cmp      #0x80,d0        ! 0c40 0080
  197.     bne    sup3        ! 6600 00fa
  198. !count of times to try converting
  199. !--maybe they can't stop the clock
  200.     move    #2000,count(a6)        ! 3d7c 07d0 fffc
  201.     bra    sup1        ! 6000 00e8
  202. sup2:
  203. !get char 0xa
  204.     move    #0xa,-(a7)        ! 3f3c 000a
  205.     move    chan(a6),-(a7)        ! 3f2e fffe
  206.     jsr    getsupclk        ! 4eb9 0000 00e8
  207.     add.l    #4,a7        ! 588f
  208.     and      #0x80,d0        ! c07c 0080
  209.     tst      d0        ! 4a40
  210.     bne    sup1        ! 6600 00ce
  211.  
  212. !get char 0x9 - year
  213.     move    #0x9,-(a7)        ! 3f3c 0009
  214.     move    chan(a6),-(a7)        ! 3f2e fffe
  215.     jsr    getsupclk        ! 4eb9 0000 00e8
  216.     add.l    #4,a7        ! 588f
  217.     sub      #80,d0        ! 907c 0050
  218.     asl      #1,d0        ! e340
  219.     asl      #8,d0        ! e140
  220.     move    d0,date(a6)        ! 3d40 fffa
  221. !get char 0x8 - month
  222.     move    #0x8,-(a7)        ! 3f3c 0008
  223.     move    chan(a6),-(a7)        ! 3f2e fffe
  224.     jsr    getsupclk        ! 4eb9 0000 00e8
  225.     add.l    #4,a7        ! 588f
  226.     asl      #5,d0        ! eb40
  227.     or      d0,date(a6)        ! 816e fffa
  228. !get char 0x7
  229.     move    #0x7,-(a7)        ! 3f3c 0007
  230.     move    chan(a6),-(a7)        ! 3f2e fffe
  231.     jsr    getsupclk        ! 4eb9 0000 00e8
  232.     add.l    #4,a7        ! 588f
  233.     or      d0,date(a6)        ! 816e fffa
  234.  
  235. !time format:
  236. ! 0-4    (1f)    2sec    0-29
  237. ! 5-10    >>5 (3f) min    0-59
  238. ! 11-15    >>11 (3f) hour    0-59
  239. !get char 0x4 hour
  240.     move    #0x4,-(a7)        ! 3f3c 0004
  241.     move    chan(a6),-(a7)        ! 3f2e fffe
  242.     jsr    getsupclk        ! 4eb9 0000 00e8
  243.     add.l    #4,a7        ! 588f
  244.     asl      #3,d0        ! e740
  245.     asl      #8,d0        ! e140
  246.     move    d0,time(a6)        ! 3d40 fff8
  247. !get char 0x2 min
  248.     move    #0x2,-(a7)        ! 3f3c 0002
  249.     move    chan(a6),-(a7)        ! 3f2e fffe
  250.     jsr    getsupclk        ! 4eb9 0000 00e8
  251.     add.l    #4,a7        ! 588f
  252.     asl      #5,d0        ! eb40
  253.     or      d0,time(a6)        ! 816e fff8
  254. !get char 0x0 seconds - 2 sec 0-29
  255.     clr      -(a7)        ! 4267
  256.     move    chan(a6),-(a7)        ! 3f2e fffe
  257.     jsr    getsupclk        ! 4eb9 0000 00e8
  258.     add.l    #4,a7        ! 588f
  259.     or      d0,time(a6)        ! 816e fff8
  260. !
  261.     move    date(a6),d0
  262.     asl.l    #8,d0
  263.     asl.l    #8,d0
  264.     move    time(a6),d0
  265. !return a long date | time in TOS format
  266.     bra    sup3        ! 6008
  267. sup1:
  268.     sub      #1,count(a6)        ! 536e fffc
  269.     bne    sup2        ! 6600 ff14
  270.     clr.l    d0         !timed out
  271. sup3:
  272.     unlk    a6        ! 4e5e
  273.     rts        ! 4e75
  274.  
  275.     .sect    .data
  276.  
  277.  
  278. dma_mode_a:
  279.     .data4     0xff8606
  280. gpip_a:
  281.     .data4     0xfffa01
  282. dma_data_a:
  283.     .data4     0xff8604
  284.  
  285.  
  286. ! ICD clock handler
  287.  
  288.         .sect   .text
  289.  
  290. get_datetime:
  291.     bsr    start_io    
  292.     bmi    badread    
  293.     lea    field_size,a1    
  294.     move    #0x5,d1    
  295.     move    #0x0,d7    
  296. get_loop:
  297.     move.b    0x0(a1,d1.w),d2    
  298.     and      #0xf,d2    
  299.     lsl.l    d2,d7    
  300.     bsr    do_io    
  301.     bmi    badread    
  302.     or.l    d0,d7    
  303.     dbf    d1,get_loop    
  304.     move.l    d7,d0    
  305. badread:
  306.     bsr    end_io    
  307.     tst      d2    
  308.     rts    
  309. start_io:
  310.     lea    0xffff8604,a0    
  311.     move    #0x88,0x2(a0)    
  312.     move    #0xc0,(a0)    
  313.     move    #0x8a,0x2(a0)    
  314.     nop    
  315.     btst    #0x5,0xfffffa01    
  316.     beq    io_done    
  317.     move    #-0x1,d2    
  318.     rts    
  319. io_done:
  320.     move    #0x0,d2    
  321.     rts    
  322. end_io:
  323.     move    #0x40,(a0)    
  324.     move    #0x80,0x2(a0)    
  325.     rts    
  326. do_io:
  327.     bsr    h1c6    
  328.     bmi    h1be    
  329.     move.l    a1,-(a7)    
  330.     lea    clk_codes,a1    
  331.     clr.l    d2    
  332.     move.b    0x0(a1,d1.w),d2    
  333.     move.l    (a7)+,a1    
  334.     move    d2,(a0)    
  335.     or      #0x20,d2    
  336.     move    d2,(a0)    
  337.     and      #0xcf,d2    
  338.     move    d2,(a0)    
  339.     and      #0x8f,d2    
  340.     move    d2,(a0)    
  341.     add      #0x0,d2    
  342.     move    (a0),d0    
  343.     move    #0xc0,(a0)    
  344.     and      #0xf,d0    
  345.     cmp      #0x85,d2    
  346.     bne    h176    
  347.     and      #0x3,d0    
  348. h176:
  349.     mulu    #0xa,d0    
  350.     move    d0,-(a7)    
  351.     or      #0xc0,d2    
  352.     sub       #1,d2    
  353.     move    d2,(a0)    
  354.     or      #0x20,d2    
  355.     move    d2,(a0)    
  356.     and      #0xcf,d2    
  357.     move    d2,(a0)    
  358.     and      #0x8f,d2    
  359.     move    d2,(a0)    
  360.     add      #0x0,d2    
  361.     move    (a0),d0    
  362.     move    #0xc0,(a0)    
  363.     and      #0xf,d0    
  364.     add      (a7)+,d0    
  365.     tst      d1    
  366.     bne    h1ac    
  367.     lsr      #1,d0    
  368. h1ac:
  369.     and.l    #0xff,d0    
  370.     cmp       #0x5,d1    
  371.     bne    h1bc    
  372.     sub      #0x50,d0    
  373. h1bc:
  374.     move    #0x0,d2    
  375. h1be:
  376.     rts    
  377. ! some indexes (maybe to the clock chip
  378. clk_codes:
  379.     .data1    0xc1,0xc3
  380.     .data1    0xc5,0xc8
  381.     .data1    0xca,0xcc
  382. h1c6:
  383.     move    #0x0,d2    
  384.     rts    
  385.  
  386. !date format:
  387. ! 0-4    (1f)    day    1-31
  388. ! 5-8    >>5 (f)    month    1-12
  389. ! 9-15    >>9 (7f) year    0-119  year 0 == 1980
  390. !
  391. !time format:
  392. ! 0-4    (1f)    2sec    0-29
  393. ! 5-10    >>5 (3f) min    0-59
  394. ! 11-15    >>11 (3f) hour    0-59
  395. !
  396. field_size:
  397. h1ca:
  398.     .data1    0x05    !second size (2 second resolution)
  399.     .data1    0x06    !minute size
  400.     .data1    0x05    !hour size
  401.     .data1    0x05    !day size
  402.     .data1    0x04    !month size
  403.     .data1    0x07    !year size
  404.  
  405. !returns long in d0
  406. ! |date word| time word|
  407. _geticd:
  408.     movem.l    d2-d7/a2-a7,-(a7)
  409.     bsr    get_datetime    
  410.     bmi    bad_read    
  411. return:
  412.     m